<?php
/**
 *
 * 功能描述（评论数据）
 *
 * @author suoya <jlusuoya@gmail.com>
 * @version 1
 */

class ModelComment extends ModelBase
{
	function GetGoodsComments($goodsId, $page)
	{
		$where = "visible = 1 and goods_id = $goodsId";
		$data  = $this->db->getRow("goods_comment", 'count(1) cnt', $where);
		if($data['cnt'] == 0)
			return array('cnt' => 0, 'pageCnt' => 0, 'data' => array());

		$comments = array('cnt' => $data['cnt'], 'pageCnt' => ceil($data['cnt'] / COMMENT_PAGESIZE));
		$limit = COMMENT_PAGESIZE * ($page - 1) . ", " . COMMENT_PAGESIZE;
		$data = $this->db->getAll("goods_comment", "username, createtime, content, taste, service, whole, `size`", $where, 'createtime desc', $limit);
		foreach($data as $k => $item)
			$data[$k]['username'] = replace_star($item['username']);
		$comments['data'] = $data;
		return $comments;
	}

	function AddComment($data)
	{
		$id = $this->db->Insert("goods_comment", $data);
		return $id;
	}
}

